package com.ptadmin.report.output;

import org.bson.Document;

import com.google.gson.Gson;
import com.mongodb.client.MongoDatabase;
import com.ptadmin.report.mongo.MongoDaoImpl;
import com.ptadmin.report.mongo.MongoHelper;

public class MongoDbOutput extends Output {

	MongoHelper mongo = new MongoHelper();
	MongoDatabase mongoDb = mongo.getMongoDataBase();
	MongoDaoImpl dao = new MongoDaoImpl();
	
	Document document;
	Gson gson = new Gson();
	
	public MongoDbOutput(Object obj) {
		String json = gson.toJson(obj);
		this.document = Document.parse(json);
	}
	
	@Override
	public void output(String path) {
		try {
			dao.insert(mongoDb, path, this.document);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
